/**
 * 
 */
package com.zufangbao.earth.task;

import java.io.IOException;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.zufangbao.sun.entity.company.corp.AppAccount;
import com.zufangbao.sun.service.AppService;
import com.zufangbao.sun.service.DeductService;
import com.zufangbao.sun.service.PayService;

/**
 * @author wk 工行银企直连服务
 */
@Component
public class ICBCDirectConnectTask {

  @Autowired
  private PayService autoPayService;
  @Autowired
  private DeductService deductService;
  @Autowired
  private AppService appService;
  private static final Log logger = LogFactory
      .getLog(ICBCDirectConnectTask.class);

  /** 定时调度 自动匹配 */
  @Scheduled(fixedDelay = 180000)
  public void DeductAndService() throws IOException, Throwable {
    logger.info("start ***************============");
    List<AppAccount> appAccountList = appService.queryAppsUseDirectBank();
    for (AppAccount appAccount : appAccountList) {
      try {
        /** 取流水服务 */
        boolean isGetFlowSuc = deductService
            .handleFlowOfApp(appAccount);
        logger.info("getFlowOfApp " + isGetFlowSuc);
        /** 自动匹配*/
        logger.info("*************start handleReceiveOrderMap**************");
        deductService.handleReceiveOrderMap(appAccount);
        logger.info("*************end handleReceiveOrderMap**************");
        
      } catch (Exception ex) {
        logger.error(ex);
      }
    }
    logger.info("end ***************============\n");
  }

}
